from haystack import indexes
from goods.models import Goods

class GoodsIndex(indexes.SearchIndex,indexes.Indexable):
    text = indexes.CharField(document=True,use_template=True)
    # goods_brief = indexes.CharField(model_attr="goods_brief")
    # goods_price = indexes.CharField(model_attr="goods_price")
    # goods_front_image = indexes.CharField(model_attr="goods_front_image")
    created = indexes.CharField(model_attr='add_time')

    @staticmethod
    def prepare_autocomplete(obj):
        return "".join((
            obj.goods_brief
        ))

    def get_model(self):
        return Goods

    def index_queryset(self,using=None):
        return self.get_model().objects.all()

